package com.sunrise.visual.frame.common
{
	public class MessageBus
	{
		private static var _instance:MessageBus;
		
		private static var _instance_created:Boolean = false;
		
		public static const INDEX_CHANGE:int = 1;
		
		public static const SWITCH_TO_PAGE:int = 2;
		
		public static const MAP_CHANGE:int = 3;
		
		public static const MAP_DIRLL:int = 4; 
		
		public static const SWITCH_TO_INDICATOR:int = 5;
		
		public static const SWITCH_TO_ITMONITOR:int = 6;
		
		public static const SWITCH_NEXT_ITMONITOR:int = 7;
		
		public static const SWITCH_PREVIOUS_ITMONITOR:int = 8;
		
		public static const BACK_TO_PARENT:int = 9;
		
		public static const VIDEO_FINISH:int = 11;

		
		/**
		 * 单例。创建要报错
		 */
		public function MessageBus()
		{
			if(_instance)
			{
				throw new Error("MessageBus单例模式");
			} else {
				_instance_created = true;
			}
		}
		
		/**
		 * 得到机器人管理器单例
		 */
		public static function get instance():MessageBus
		{
			if ( _instance == null )
			{
				_instance = new MessageBus();
			}
			return _instance;
		}
		
		public function send(type:int,param:Object):void {
			for each(var obj:Object in listener) {
				if(obj.type == type) {
					var func:Function = obj.func as Function;
					func.call(null, param);
				}
			}
		}
		
		public function addListener(type:int, func:Function):void {
			if(func == null) return;
			var obj:Object = new Object();
			obj.type = type;
			obj.func = func;
			listener.push(obj);
		}
		
		private var listener:Array = new Array();
	}
}